package com.skill.shareskill.activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.skill.shareskill.R;
import com.skill.shareskill.bean.ActivityItem;
import com.skill.shareskill.service.LoadDataThread;
import com.skill.shareskill.utils.HttpUtils;

public class DetailActivityActivity extends AppCompatActivity {
    private ActivityItem activity;
    private ImageView iv_detail_act_icon;
    private TextView tv_detail_act_price;
    private TextView tv_detail_act_type;
    private TextView tv_detail_act_name;
    private TextView tv_detail_act_describe;
    private TextView tv_detail_act_attention;
    private TextView tv_detail_act_evaluate;
    private String actname;
    private String actprice;
    private ImageView iv_detail_return;
    private Gson gson=new Gson();
    private Handler handler=new Handler(){
        public void handleMessage(Message message){
            String activityJson= (String) message.obj;
            Log.d("network", "sb==>" + activityJson);
            // activityBean=gson.fromJson(activityJson,ActivityBean.class);
            activity=gson.fromJson(activityJson,ActivityItem.class);
            if(activity!=null){
                Glide.with(DetailActivityActivity.this)
                        .load(HttpUtils.BASE_PATH+activity.getActImg())
                        .placeholder(R.drawable.pic1)
                        .error(R.drawable.pic2)
                        .into(iv_detail_act_icon);
                tv_detail_act_price.setText(activity.getActPrice()+"");
                tv_detail_act_type.setText(activity.getActType()+"");
                tv_detail_act_name.setText(activity.getActName());
                tv_detail_act_describe.setText(activity.getActDescribe());
                tv_detail_act_attention.setText(activity.getActAttention());
            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detail_activity);
        tv_detail_act_name=findViewById(R.id.tv_detail_act_name);
        iv_detail_act_icon=findViewById(R.id.iv_detail_act_icon);
        tv_detail_act_price=findViewById(R.id.tv_detail_act_price);
        tv_detail_act_type=findViewById(R.id.tv_detail_act_type);
        tv_detail_act_describe=findViewById(R.id.tv_detail_act_describe);
        tv_detail_act_attention=findViewById(R.id.tv_detail_act_attention);
        tv_detail_act_evaluate=findViewById(R.id.tv_detail_act_evaluate);
        iv_detail_return=findViewById(R.id.iv_detail_return);
        Intent intent = getIntent();
        actname =  intent.getStringExtra("name");
        actprice=intent.getStringExtra("price");
        tv_detail_act_type.setText(actname);
        tv_detail_act_price.setText(actprice+"￥");
        /*Intent intent=getIntent();
        String actNo=intent.getStringExtra("actNo");
        String activityUrl=HttpUtils.BASE_PATH+"activity/queryActivityByActNo?actNo="+actNo;
        LoadDataThread lat=new LoadDataThread(handler,activityUrl);
        lat.start();*/
        iv_detail_return.setOnClickListener(new View.OnClickListener(){

            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }
}
